<include file="Public/head" />
	<div class="tableContainer">
		<div class="tablePanel">
			<div class="edit-title">
				<!-- 有title-icon1至title-icon14共14个图标可供选择 -->
				<span class="title-icon14"></span>
				<div>&nbsp;&nbsp;<{:$item['id']?'修改':'添加'}>图文回复</div>
			</div>
	        <form id="memberform" onsubmit="return false;">
				<input type="hidden" name="info[id]" value="<{$item.id}>" />
				<input type="hidden" name="info[type]" value="2" />
				<div class="edit-body">
					<div class="set-line">
						<div class="set-title">关键词：</div>
						<div class="set-ctrl">
							<input name="info[keyword]" value="<{$item.keyword}>" type="text" />
						</div>
					</div>
					<div class="set-line">
						<div class="set-title">标题：</div>
						<div class="set-ctrl">
							<input name="info[title]" value="<{$item.title}>" type="text" />
						</div>
					</div>
					<div class="set-line">
						<div class="set-title">配图：</div>
						<div class="set-ctrl">
							<div class="uploadWrapper">点击上传
								<input class="uploadFile" type="file" id="pic" name="pic" onchange="upload_img('pic',540,300)" />
							</div>
							<input type="hidden" name="info[pic]" value="<{$item.pic}>" />
							<span style="color:#666;">&nbsp;&nbsp;&nbsp;建议尺寸 540x300像素</span>
						</div>
					</div>
					<div class="set-line" <if condition="$item['pic'] eq ''">style="display:none;"</if>>
						<div class="set-title"></div>
						<div class="set-ctrl">
							<div class="showImgDiv">
								<img src="<{:$item['pic'] ? C('IMG_PREFIX').$item['pic'] : ''}>" />
							</div>
						</div>
					</div>
					<div class="set-line">
						<div class="set-title">跳转链接：</div>
						<div class="set-ctrl">
							<input name="info[url]" value="<{$item.url}>" type="text" />&nbsp;&nbsp;&nbsp;如：http://www.baidu.com
						</div>
					</div>
					<div class="set-line">
						<div class="set-title">图文描述：</div>
						<div class="set-ctrl">
							<textarea name="info[content]" class="textField" style="width:400px;height:150px;" placeholder="选填"><{$item.content}></textarea>
						</div>
					</div>
					<div class="set-line">
						<div class="set-title">状态：</div>
						<div class="set-ctrl">
							<label class="radioLabel">
								<input type="radio" name="info[state]" <{:$item['state']!='2'?'checked': ''}> value='1' /> 开放
							</label>
							<label class="radioLabel">
								<input type="radio" name="info[state]" <{:$item['state']=='2'?'checked': ''}> value='2'/> 关闭
							</label>
						</div>
					</div>
					<div class="clearfloat"></div>
					<div class="save">
						<span id="save" class="saveBtn" onclick="save(this)" style="float:left;">保 存</span>
						<span onclick="history.go(-1);" class="saveBtn" style="float:left;margin-left:16px;">返回</span>
					</div>
				</div>
			</form>
		</div>
	</div>
	<!-- 上传图片开始 -->
	<script type='text/javascript' src='__PUBLIC__/js/ajaxfileupload.js'></script>
	<script type="text/javascript">
	    //width height 要压缩成的图片宽 高，默认0代表不限制
	    function upload_img(id, width, height){
	        if(id == '' || id == null) return;
	        if(!width) width = 0;
	        if(!height) height = 0;

	        var loadIndex = layer.load(1);
	        $.ajaxFileUpload ({
	             url: '<{:U('Admin/PicUpload/index')}>',
	             data: {width: width, height: height},
	             secureuri: false,
	             fileElementId: id,
	             dataType: 'json',
	             success: function (data,status){
	                layer.close(loadIndex);
	                if(data.status){
						$('#'+id).parents('.set-line').next().children().find('img').attr('src', '<{:C("IMG_PREFIX")}>'+data.info);
						$('#'+id).parents('.set-line').next().show();
		                $('#'+id).parent().siblings('input').val(data.info);
	                }else{
	                    note_info(data.info,$('#'+id),'warn')
	                }
	             }
	        });
	    }
	</script>
	<!-- 上传图片结束 -->
	<script>
	function save(obj){
		if($("input[name='info[keyword]']").val()==''){
			note_info('请填写关键词',obj,'warn');return;
		}
		if($("input[name='info[title]']").val()==''){
			note_info('请填写标题',obj,'warn');return;
		}
		if($("input[name='info[pic]']").val()==''){
			note_info('请上传图片',obj,'warn');return;
		}
		if(!isUrl($("input[name='info[url]']").val())){
			note_info('请请填写正确的链接',obj,'warn');return;
		}
		
		$.post("<{:U('Wechat/WxCommon/add')}>",$('#memberform').serialize(),function(res){
			if(res.status == 1){
				note_info(res.info,obj);
				setTimeout('window.location.href="<{$upPageUrl}>"',1200);
			}else{
				note_info(res.info,obj,'warn');
			}
		},'json');
	}
	
	//判断URL
	function isUrl(str){
		var RegUrl = new RegExp();
		RegUrl.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
		if (!RegUrl.test(str)){
			return false;
		}
		return true;
	}
	</script>
<include file="Public/foot" />